<?php
defined('JOC') or die;
/*-------------------------------------------------------|
 * Model Class.                                          +
 * ------------------------------------------------------|
 * Description :                                         +
 * It contains common methos for new models classes.     +
 * ------------------------------------------------------|
 * @author : Javier Oscar Camelis                        |
 * ------------------------------------------------------|
 */
class Page_model extends Model {
  /*-------------------------------------------------------|
   * DataBase table name.                                  +
   * ------------------------------------------------------|
   * Description :                                         +
   * The name of the table that this model will control    +
   * ------------------------------------------------------|
   */
  protected $_table_name  = 'page' ;
  /*-------------------------------------------------------|
   * Primary Key.                                          +
   * ------------------------------------------------------|
   * Description :                                         +
   * Primary Key DataBase table name                       +
   * ------------------------------------------------------|
   */
  protected $_pk_name     = 'page_id' ;
  /*-------------------------------------------------------|
   * Select_by_title                                       +
   * ------------------------------------------------------|
   * Description :                                         +
   * Select the page requested with all its associated     +
   * properties.                                           +
   * ------------------------------------------------------|
   * @params :                                             +
   * $title : The title of page witch must match.          +
   * ------------------------------------------------------|
   * @return : $this                                       +
   * ------------------------------------------------------|
   */
  public function Select_by_title($title = '')
  {
    $sql = "SELECT P.* , T.path AS theme , PT.title as template_title , 
          PT.file_name as template_file 
          FROM {prefix}page AS P 
          INNER JOIN {prefix}page_template AS PT ON PT.page_template_id = P.page_template_id
          INNER JOIN {prefix}theme AS T ON T.theme_id = P.theme_id
          WHERE P.title = '{$title}' LIMIT 1 ; " ;

    $this->_last_result = $this->db()->query($sql) ;
    return $this ;
  }
  /*-------------------------------------------------------|
   * Filter_by_title                                       +
   * ------------------------------------------------------|
   * Description :                                         +
   * Filter the rows saved on $this->_last_result          +
   * ------------------------------------------------------|
   * @params :                                             +
   * $title : The title of page witch must match.          +
   * ------------------------------------------------------|
   * @return : The row filtered                            +
   * ------------------------------------------------------|
   */
  function Filter_by_title($title = '')
  {
    if($title && $this->num_rows() > 0)
    {
      $tmp = Array() ;
      foreach($this->_last_result as $row)
      {
        if($row['title'] === $title)
        {
          $tmp = $row ;
        }
      }
      return $tmp ;
    }
  }
}
/*
 * ---------------------------------------------------------+
 * End of file page_model.class.php                         |
 * ---------------------------------------------------------+
 * located at core/model/page_model.class.php               |
 * ---------------------------------------------------------+
*/